<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UserRequest extends BaseRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        $method = $this->method();
        return [
            'phone' => 'bail|required|string|regex:/^1[3-9]\d{9}$/',
            'verifyCode' => 'bail|required|size:6',
            'nickname' => 'nullable|min:2|max:8',
            'password' => 'required|string|min:6|confirmed', // 密码必填，至少6位，需与password_confirmation一致
        ];
    }

    public function messages(): array
    {
        return [
            'phone.required' => '手机号为必填项',
            'phone.string' => '手机号必须为字符串',
            'phone.regex' => '请输入有效的11位手机号',
            'verifyCode.required' => '验证码为必填项',
            'verifyCode.size' => '验证码必须为6位数字',
            'password.required' => '密码不能为空',
            'password.min' => '密码至少需要6个字符',
            'password.confirmed' => '两次输入的密码不一致',
            'nickname.min' => '至少两位字符',
            'nickname.max' => '不能超过8位字符'
        ];
    }
}
